﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace BluewaterSoft.Notepad
{
  public sealed partial class ExtendedSplash : UserControl
  {
    // Sample: http://code.msdn.microsoft.com/windowsapps/Splash-screen-sample-89c1dc78

    private Rect splashImageCoordinates; // Rect to store splash screen image coordinates. 
    private SplashScreen splash; // Variable to hold the splash screen object. 
    private bool dismissed = false; // Variable to track splash screen dismissal status. 

    public ExtendedSplash(SplashScreen splashScreen, bool dismissed)
    {
      this.InitializeComponent();

      this.splashImageCoordinates = splashScreen.ImageLocation;
      this.splash = splashScreen;
      this.dismissed = dismissed;

      // Position the extended splash screen image in the same location as the splash screen image. 
      this.extendedSplashImage.SetValue(Canvas.LeftProperty, this.splashImageCoordinates.X);
      this.extendedSplashImage.SetValue(Canvas.TopProperty, this.splashImageCoordinates.Y);
      this.extendedSplashImage.Height = this.splashImageCoordinates.Height;
      this.extendedSplashImage.Width = this.splashImageCoordinates.Width;

      Window.Current.SizeChanged += new WindowSizeChangedEventHandler(ExtendedSplash_OnResize);
      
    }

    void ExtendedSplash_OnResize(Object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
      // Safely update the splash screen image coordinates 
      if (this.splash == null)
        return;

      this.splashImageCoordinates = this.splash.ImageLocation;

      // Re-position the extended splash screen image due to window resize event. 
      this.extendedSplashImage.SetValue(Canvas.LeftProperty, this.splashImageCoordinates.X);
      this.extendedSplashImage.SetValue(Canvas.TopProperty, this.splashImageCoordinates.Y);
      this.extendedSplashImage.Height = this.splashImageCoordinates.Height;
      this.extendedSplashImage.Width = this.splashImageCoordinates.Width;
    }


    /// <summary> 
    /// Event handler for dismissed event to know when the Splash screen is dismissed 
    /// </summary> 
    /// <param name="sender">SplashScreen</param> 
    internal void DismissedEventHandler(Windows.ApplicationModel.Activation.SplashScreen sender, object e)
    {
      this.dismissed = true;
    }


    

  }
}
